import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: JSON.parse(sessionStorage.getItem("userInfo"))
  },
  mutations: {
    SET_TOKEN: (state,token) => {
      state.token = token
      //数据存储到浏览器
      localStorage.setItem("token",token)
    },
    SET_USERINRO: (state,userInfo) => {
      state.userInfo = userInfo
      //sessionStorage不能存一个对象
      sessionStorage.setItem("userInfo",JSON.stringify(userInfo))
    },
    REMOVE_INFO: (state) => {
      state.token = ''
      state.userInfo = ''
      localStorage.setItem("token","")
      sessionStorage.setItem("userInfo","")
    }
  },
  getters: {
    getUser: state => {
      return state.userInfo
    }
  },
  actions: {
  },
  modules: {
  }
})
